﻿
using FairyGUI;
/// <summary>
/// 设置界面
/// </summary>
public class UISettingWindow : UIPopupWindow {

    /// <summary>
    /// 音效滑动条
    /// </summary>
    GSlider _musicEfCtrl;

    /// <summary>
    /// 音乐滑动条
    /// </summary>
    GSlider _musicCtrl;

	public UISettingWindow()
    {
        // 加载界面
        base.Init(UIPackage.CreateObject("大厅", "设置界面").asCom);

        GComponent settingComp = uiComp.GetChild("设置组件").asCom;

        // 初始化关闭按钮
        GButton closeBtn = settingComp.GetChild("关闭按钮").asButton;
        closeBtn.onClick.Add(() => {
            DebugInfo.Log("关闭设置界面");

            AudioController.inst.PlayUIClickEffect();
            AudioController.inst.SavePreference();
            uiComp.RemoveFromParent();
            uiComp.Dispose();
            base.Close();
        });

        // 初始化退出登录按钮
        GButton exitBtn = settingComp.GetChild("退出登录按钮").asButton;
        exitBtn.onClick.Add(() => {
            DebugInfo.Log("退出登录");

            AudioController.inst.PlayUIClickEffect();
            AudioController.inst.SavePreference();
            uiComp.RemoveFromParent();
            uiComp.Dispose();
            base.Close();

            GameController.inst.Logout();
        });

        _musicEfCtrl = settingComp.GetChild("音效滑动条").asSlider;
        _musicEfCtrl.onChanged.Add(()=> {
            AudioController.inst.effectVolume = (float)(_musicEfCtrl.value * 0.01);
        });
        _musicEfCtrl.value = AudioController.inst.effectVolume * 100;


        _musicCtrl = settingComp.GetChild("音乐滑动条").asSlider;
        _musicCtrl.onChanged.Add(() => {
            AudioController.inst.musicVolume = (float)(_musicCtrl.value * 0.01);
        });
        _musicCtrl.value = AudioController.inst.musicVolume * 100;
    }

    /// <summary>
    /// 弹出窗口
    /// </summary>
    public static void Popup()
    {
        DebugInfo.Log("打开设置界面");
        UIRootController.inst.PopupWindow(new UISettingWindow());
    }
}
